﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace WebApp
{
    public partial class Manager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //调用母版页对象
            //this.txtStudNo.Text = ((Label)this.Master.FindControl("lblUserName")).Text;
        }     

        
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   ManagerName, Gender FROM      ManagerInfo  WHERE   (ManagerNo = @ManagerNo)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@ManagerNo", this.txtMNo.Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.txtMName.Text = dr["ManagerName"].ToString();
                this.txtMGender.Text = dr["Gender"].ToString();
                
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('已成功查询！')", true);

            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('查询失败！您尚未编辑您的个人基本信息！')", true);
            }
            dr.Close();
        }

        protected void btnUpdata_Click(object sender, EventArgs e)
        {
            try
            {

                StringBuilder SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("UPDATE  ManagerInfo ");
                SqlStringBuilder.AppendFormat("SET     ManagerName = N'{0}', Gender = N'{1}' ", this.txtMName.Text, this.txtMGender.Text);
                SqlStringBuilder.AppendFormat("WHERE   (ManagerNo = N'{0}') ", this.txtMNo.Text);

                int iUpd = SqlHelper.ExecuteNonQuery(SqlStringBuilder.ToString());
                if (iUpd > 0)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('更新成功！已更新" + iUpd.ToString() + "条记录！')", true);
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = "更新失败！请重新编辑……具体原因：" + ex.Message;
            }
        }

        protected void btnNewT_Click(object sender, EventArgs e)
        {
            this.txtMNo.Text = "";
            this.txtMName.Text = "";
            this.txtMGender.Text = "";
        }

        protected void btnSource_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT  * FROM     ManagerInfo";

            SqlDataReader dr = SqlHelper.ExecuteReader(strSql);
            this.GridView1.DataSource = dr;
            this.GridView1.DataBind();

            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('全部数据已读取完毕！')", true);
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
                this.Theme = Session["Theme"].ToString();
        }

    }
}